# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  
  config.vm.provision "shell" do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_ed25519.pub").first.strip
    s.inline = <<-SHELL
      echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
      echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
    SHELL
  end
  
  #########
  # Consul cluster
  ###
  
  N = 3
  (1..N).each do |machine_id|
    config.vm.define "consul-#{machine_id}" do |consul|
      consul.vm.box = "gutehall/fedora40"
      consul.vm.provider "parallels" do |p|
        p.memory = "1024"
        p.cpus = "2"
      end
      consul.vm.hostname = "consul-#{machine_id}"
    end  
  end
  
  #########
  # Load balancer
  ###
  
  N = 1
  (1..N).each do |machine_id|
    config.vm.define "lb-#{machine_id}" do |lb|
      lb.vm.box = "gutehall/fedora40"
      lb.vm.provider "parallels" do |p|
        p.memory = "1024"
        p.cpus = "2"
      end
      lb.vm.hostname = "lb-#{machine_id}"
      lb.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
    end  
  end
  
  #########
  # Gateway
  ###
  
  N = 3
  (1..N).each do |machine_id|
    config.vm.define "gw-#{machine_id}" do |gw|
      gw.vm.box = "gutehall/fedora40"
      gw.vm.provider "parallels" do |p|
        p.memory = "1024"
        p.cpus = "2"
      end
      gw.vm.hostname = "gw-#{machine_id}"
    end  
  end
  
  #########
  # Service
  ###
  
  N = 2
  (1..N).each do |machine_id|
    config.vm.define "srv-#{machine_id}" do |srv|
      srv.vm.box = "gutehall/fedora40"
      srv.vm.provider "parallels" do |p|
        p.memory = "1024"
        p.cpus = "2"
      end
      srv.vm.hostname = "srv-#{machine_id}"
    end  
  end
  
end
